package org.googlecode.jwf.demo;

import per.edward.wizard.ext.CustomDescriptor;

public class ProcessDesc extends CustomDescriptor {

    private ProcessPanel contentPane_ = new ProcessPanel();

    public ProcessDesc() {
        setPanelDescriptorIdentifier(ProcessPanel.class.getName());
        setWrappedPanelComponent(contentPane_);
    }

    @Override
    public void aboutToDisplayPanel() {

        contentPane_.setProgressValue(0);
        contentPane_.setProgressText("Connecting to Server...");

        getWizard().setNextFinishButtonEnabled(false);
        getWizard().setBackButtonEnabled(false);

    }

    @Override
    public void displayingPanel() {
        Thread t = new Thread() {
            public void run() {
                try {
                    Thread.sleep(2000);
                    contentPane_.setProgressValue(25);
                    contentPane_
                            .setProgressText("Server Connection Established");
                    Thread.sleep(500);
                    contentPane_.setProgressValue(50);
                    contentPane_.setProgressText("Transmitting Data...");
                    Thread.sleep(3000);
                    contentPane_.setProgressValue(75);
                    contentPane_
                            .setProgressText("Receiving Acknowledgement...");
                    Thread.sleep(1000);
                    contentPane_.setProgressValue(100);
                    contentPane_
                            .setProgressText("Data Successfully Transmitted");

                    getWizard().setNextFinishButtonEnabled(true);
                    getWizard().setBackButtonEnabled(true);

                } catch (InterruptedException e) {

                    contentPane_.setProgressValue(0);
                    contentPane_.setProgressText("An Error Has Occurred");

                    getWizard().setBackButtonEnabled(true);
                }
            }
        };
        t.start();
    }
}
